package wc

import (
	"fmt"
	"io/ioutil"
	"main/env"
	"main/protos"
	"net/http"
)

const (
	CTXLoveMode   = "love_mode"
	PreLove       = "prelove"
	CTXLoveBuffer = "love_buffer"
)

func RunLoveModule(params string) string {
	res, err := http.Get(fmt.Sprintf("http://%s:80/?%s", env.LoveServer, params))
	if err != nil {
		return err.Error()
	}
	defer res.Body.Close()

	content, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err.Error()
	}

	var bm protos.BaseMessage
	err = bm.XXX_Unmarshal(content)
	if err != nil {
		return err.Error()
	}
	return string(bm.Data)
}
